<template>
  <div>
    <!--引用表格-->
    <BasicTable @register="registerTable" :rowSelection="rowSelection">
      <!--插槽:table标题-->
      <template #tableTitle> </template>
      <!--操作栏-->
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" />
      </template>
      <!--字段回显插槽-->
      <template #htmlSlot="{ text }">
        <div v-html="text"></div>
      </template>
      <!--省市区字段回显插槽-->
      <template #pcaSlot="{ text }">
        {{ getAreaTextByCode(text) }}
      </template>
      <template #fileSlot="{ text }">
        <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
        <a-button v-else :ghost="true" type="primary" preIcon="ant-design:download-outlined" size="small" @click="downloadFile(text)">下载</a-button>
      </template>
    </BasicTable>
  </div>
</template>

<script lang="ts" name="basCustomer-basCustomer" setup>
import { ref, computed, unref } from 'vue';
import { BasicTable, useTable, TableAction } from '/@/components/Table';
import { useListPage } from '/@/hooks/system/useListPage';
import { columns, searchFormSchema } from './StockCloseAccount.data';
import { list, cancelMonthlySettlement, monthlySettlement } from './StockCloseAccount.api';
import { downloadFile } from '/@/utils/common/renderUtils';
import { usePermission } from '/@/hooks/web/usePermission';
const { hasPermission } = usePermission();
const checkedKeys = ref<Array<string | number>>([]);

//注册table数据
const { prefixCls, tableContext, onExportXls, onImportXls } = useListPage({
  tableProps: {
    title: '库存关账',
    api: list,
    columns,
    canResize: false,
    formConfig: {
      labelWidth: 40,
      schemas: searchFormSchema,
      autoSubmitOnEnter: true,
      showAdvancedButton: true,
      fieldMapToNumber: [],
      fieldMapToTime: [],
    },
    actionColumn: {
      width: 160,
      fixed: 'right',
    },
  },
});

const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext;

/**
 * 月结事件
 */
async function handlemonthlySettlement(record) {
  await monthlySettlement({ id: record.id }, handleSuccess);
}
/**
 * 取消月结事件
 */
async function handlcancelMonthlySettlement(record) {
  await cancelMonthlySettlement({ id: record.id }, handleSuccess);
}
/**
 * 成功回调
 */
function handleSuccess() {
  (selectedRowKeys.value = []) && reload();
}
/**
 * 操作栏
 */
function getTableAction(record) {
  return [
    {
      label: '月结',
      popConfirm: {
        title: '是否确认月结',
        confirm: handlemonthlySettlement.bind(null, record),
      },
      ifShow: record.periodStatus == 0 ? true : false,
      auth: 'base:stockCloseAccount:monthlySettlement', //通过权限指令控制显示（有权限显示/无权限不显示）
    },
        {
      label: '取消月结',
      popConfirm: {
        title: '是否确认月结',
        confirm: handlcancelMonthlySettlement.bind(null, record),
      },
      ifShow: record.periodStatus == 1 ? true : false,
      auth: 'base:stockCloseAccount:cancelMonthlySettlement', //通过权限指令控制显示（有权限显示/无权限不显示）
    },
  ];
}

</script>

<style scoped>
</style>